<template>
  <div>
    <w-nav-bar
      v-if="navTitle"
      :title="navTitle"/>
    <w-cell
      v-for="(v, k) in dataArr"
      :link="linkKey ? v[linkKey] : null"
      :key="k"
      :icon="v[iconKey]"
      :header="v[headerKey]"
      :detail="v[detailKey]"
      :time="v[timeKey]"
      @click="cellClick(v)"/>
    <w-dustbin
      ref="WDustbin"
      @reload="loadAll"/>
    <w-load-more :finish="true"/>
  </div>
</template>

<script>
  import WCell from '@/components/mobile/cell/index'
  import WDustbin from '../dustbin/index'
  import WLoadMore from '@/components/global/loadMore'
  export default {
    name: "ComListAll",
    components: {
      WCell,
      WDustbin,
      WLoadMore
    },
    props: {
      classModel: {
        type: Function,
        default: () => {}
      },
      pathName: {
        type: String,
        default: ''
      },
      iconKey: {
        type: String,
        default: ''
      },
      headerKey: {
        type: String,
        default: ''
      },
      detailKey: {
        type: String,
        default: ''
      },
      timeKey: {
        type: String,
        default: ''
      },
      linkKey: {
        type: String,
        default: ''
      },
      /**
       * 导航栏标题
       */
      navTitle: {
        type: String,
        default: ''
      },
      /**
       * 是否是垃圾箱
       */
      dustbin: {
        type: Boolean,
        default: false
      },
    },
    data () {
      return {
        /**
         * 数据数组
         */
        dataArr: []
      }
    },
    methods: {
      /**
       * 加载所有数据
       */
      loadAll () {
        this.classModel[this.dustbin ? 'dustbin_all' : 'loadAllModels']().w_then((data) => {
          this.dataArr = data
        })
      },
      /**
       * cell点击
       * @param item 单行数据模型
       */
      cellClick(item) {
        if (this.dustbin) {
          this.$refs['WDustbin'].show(item)
        } else {
          this.$router.push({name: this.pathName, query: {id: item._id }})
        }
      }
    },
    created() {
      this.loadAll()
    }
  }
</script>

<style scoped>

</style>
